/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.distributor.orders;

import com.sun.distributor.dao.DAO_Order;
import com.sun.distributor.dao.DAO_Product;
import com.sun.distributor.dao.DAO_Customer;
import com.sun.distributor.exceptions.InitException;
import com.sun.distributor.exceptions.QueryException;
import com.sun.distributor.exceptions.SystemException;
import com.sun.distributor.objects.Customer;
import com.sun.distributor.objects.Order;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ejb.Stateless;

/**
 *
 * @author Administrateur
 */
@WebService()
@Stateless()
public class WS_CreateOrder {

    private DAO_Order dao = null;
    private DAO_Product pdao = null;
    private DAO_Customer cdao = null;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "createOrder")
    public String createOrder(@WebParam(name = "quantity") int quantity, @WebParam(name = "product") int product, @WebParam(name = "customer") int customer) {
        try {
            //TODO write your implementation code here:
            dao = new DAO_Order();
            pdao = new DAO_Product();
//            Order ord = new Order(quantity, pdao.getProduct(product), cdao.getCustomer(customer));
            Order ord = new Order(4, pdao.getProduct(1), new Customer(1, "coucou", "coucou"));
            dao.insertOrder(ord);
            return "works";
        } catch (InitException ex) {
            return ex.toString();
        } catch (QueryException ex) {
            return ex.toString();
        } catch (SystemException ex) {
            return ex.toString();
        }
    }
}
